
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       xrce_dds_topic.c
  * @author     baiyang
  * @date       2022-4-10
  ******************************************************************************
  */

/*----------------------------------include-----------------------------------*/
#include "xrce_dds_topic.h"

#include <common/time/gp_time.h>

#include <dds_topic/xrce_dds_header.h>
#include <dds_topic/xrce_dds_helloworld.h>
/*-----------------------------------macro------------------------------------*/

/*----------------------------------typedef-----------------------------------*/

/*---------------------------------prototype----------------------------------*/
static inline void xrce_dds_topic_handle_topics(
        uxrSession* session,
        uxrObjectId object_id,
        uint16_t request_id,
        uxrStreamId stream_id,
        struct ucdrBuffer* ub,
        uint16_t length,
        void* args);
/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void xrce_dds_on_topic(
        uxrSession* session,
        uxrObjectId object_id,
        uint16_t request_id,
        uxrStreamId stream_id,
        struct ucdrBuffer* ub,
        uint16_t length,
        void* args)
{
    if (object_id.type == UXR_DATAREADER_ID) {
        xrce_dds_topic_handle_topics(session, object_id, request_id, stream_id, ub, length, args);
    }
}

/**
  * @brief       
  * @param[in]     
  * @param[out]  
  * @retval      
  * @note        
  */
void xrce_dds_topic_init()
{
    xrce_dds_header_init();
    xrce_dds_helloworld_init();
}

/**
  * @brief       
  * @param[in]     
  * @param[out]  
  * @retval      
  * @note        
  */
bool xrce_dds_topic_run()
{
    uint32_t time_now_ms = time_millis();

    return xrce_dds_helloworld_run(time_now_ms)
        && xrce_dds_header_run(time_now_ms);
}

static inline void xrce_dds_topic_handle_topics(
        uxrSession* session,
        uxrObjectId object_id,
        uint16_t request_id,
        uxrStreamId stream_id,
        struct ucdrBuffer* ub,
        uint16_t length,
        void* args)
{
    if (object_id.id == XRCE_DDS_HEADER_OBJECT_ID) {
        xrce_dds_header_on_topic(object_id, ub);
    } else if (object_id.id == XRCE_DDS_HELLOWORLD_OBJECT_ID) {
        xrce_dds_helloworld_on_topic(object_id, ub);
    }
}
/*------------------------------------test------------------------------------*/


